<template>
  <div class="root">
    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-form :inline="true" :model="query">
        <el-form-item>
          <el-input
            v-model="query.keyword"
            placeholder="请输入关键字查询"
            @click="search"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="add()">新增</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 30px;">
          <el-button type="danger" @click="BatchDelete">批量删除</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-col :span="24">
      <el-table
        v-loading="listLoading"
        :data="pageInfo.rows"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50">
        </el-table-column>
        <el-table-column prop="id" width="110" label="id">
        </el-table-column>
        <el-table-column prop="name" label="权限名称" width="400">
        </el-table-column>
        <el-table-column prop="sn" label="标识" width="400">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="small" @click="update(scope.row)" >编辑</el-button>
            <el-button type="danger" icon="el-icon-delete" circle size="small" @click="deleteById(scope.row.id)"/>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
    <el-col :span="24" style="margin-top: 20px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[5, 10]"
        :page-size="query.rows"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageInfo.total"
      >
      </el-pagination>
    </el-col>
    <el-dialog title="新增/修改" :visible.sync="saveFormVisible" :close-on-click-modal="false">
      <el-form :model="saveForm" label-width="80px" :rules="saveFormRules" ref="saveForm">
        <el-form-item label="名称" prop="name">
          <el-input v-model="saveForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="标识" prop="sn">
          <el-input v-model="saveForm.sn" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="saveFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="saveSubmit" :loading="saveLoading">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //分页相关
      query: {
        page: 1,
        rows: 5,
        keyword: "",
      },
      pageInfo: {
        total: 0, //总记录数
        rows: [], //表数据
      },
      saveFormVisible: false,
      listLoading: true,
      saveLoading:false,
      ids:[], //选中的数据
      saveFormRules: {
        name: [
          { required: true, message: '请输入名字', trigger: 'blur' }
        ],
        sn: [
          { required: true, message: '请输入标识', trigger: 'blur' }
        ]
      },
      saveForm: {
        name: "",
        sn:""
      }
    };
  },
  created() {},
  methods: {
    search() {
      this.getListPage();
    },
    //分页查询
    getListPage() {

    },
    //全选回调函数
    handleSelectionChange(value) {
      this.ids = [];
      value.forEach((d) => {
        this.ids.push(d.id);
      });
    },
    //每页条数发生改变的回调函数
    handleSizeChange(pageTotals) {
      this.query.rows = pageTotals;
      this.getListPage();
    },
    //当前页发生改变的回调函数
    handleCurrentChange(currentPage) {
      this.query.page = currentPage;
      this.getListPage();
    },
    add(){
      this.saveForm = {
        name: "",
        sn:""
      }
      this.saveFormVisible = true
    },
    update(row){
      this.saveForm = row
      this.saveFormVisible = true
    },
    //保存修改
    saveSubmit(){

    },
    deleteById(id){

    },
    BatchDelete(){

    }
  },
  mounted() {
    this.getListPage();
  },
};
</script>

<style scoped>
.root {
  margin: 30px 16px;
}
.toolbar {
  background-color: rgb(244, 243, 244);
  padding-top: 10px;
  padding-left: 10px;
  height: 60px;
}
</style>
